<template>
  <div class="user-avator-dropdown">
    <Dropdown @on-click="handleClick">
      <span style="margin-right: 10px;">{{ userName }}</span>
      <Avatar :src="userAvator"/>
      <Icon :size="18" type="md-arrow-dropdown"></Icon>
      <DropdownMenu slot="list">
        <DropdownItem name="logout">退出登录</DropdownItem>
      </DropdownMenu>
    </Dropdown>
  </div>
</template>

<script>
  import './user.less'
  import {mapActions} from 'vuex'
  import Cookies from 'js-cookie';
  import util from '../../../../libs/util';
  import Util from '../../../../libs/util';
  import Utils from '../../../../libs/mod.utils';
  import Nim from '../../../../libs/mod.nim';
  export default {
    name: 'User',
    props: {
      userAvator: {
        type: String,
        default: ''
      },
      userName: {
        type: String,
        default: ''
      }
    },
    methods: {
      ...mapActions([
        'handleLogOut'
      ]),
      handleClick (name) {
        var _this = this;
        switch (name) {
          case 'ownspace':
            this.$router.push({
              name: 'ownspace_index'
            })
            break
          case 'files':
            this.$router.push({
              name: 'file_index'
            })
            break
          case 'tags':
            this.$router.push({
              name: 'tag_index'
            })
            break
          case 'logout':
            this.handleLogOut().then(() => {
              sessionStorage.setItem('logout', 1);
              this.$router.push({
                name: 'login'
              })
            })
            Nim.loginOutNimdata();
            _this.loginOut();
            break
        }
      },
      loginOut: function () {
        var _this = this;
        setTimeout(function () {
          var data = {};
          var params = {
            url: '/user/logout',
            type: Util.method.post,
            data: data,
            success: _successFun
          };
          Util.ajax(_this, params);
          function _successFun(res) {
            if (res.result == 0) {
              console.log('退出成功');
            } else {

            }
          }
        }, 1000);
      },
    }
  }
</script>
